package com.ytsky.hctechnologysys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ytsky.hctechnologysys.dao.JobMapper;
import com.ytsky.hctechnologysys.entity.Job;
import com.ytsky.hctechnologysys.service.JobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Dell
 */
@Service
public class JobServiceImpl implements JobService {

    @Autowired
    private JobMapper jobMapper;

    @Override
    public boolean append(Job job) {
        return jobMapper.insert(job) > 0;
    }


    @Override
    public PageInfo<Job> findByKeyword(int pageNum, int pageSize, String keyword) {
        PageHelper.startPage(pageNum,pageSize);
        List<Job> jobs = jobMapper.selectByKeyword(keyword);
        PageInfo<Job>  pageInfo = new PageInfo<>(jobs);
        return pageInfo;
    }

    @Override
    public PageInfo<Job> findAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        final List<Job> jobs = jobMapper.selectAll();
        PageInfo<Job> pageInfo = new PageInfo<>(jobs);
        return pageInfo;
    }

    @Override
    public Job findById(int id) {
        return jobMapper.selectById(id);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean remove(int id) {
        return jobMapper.deleteById(id) > 0;
    }


    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean modify(Job job) {
        return jobMapper.updateById(job) > 0;
    }
}
